package com.starview.star.compiler.format.rules;

import java.util.ArrayList;
import java.util.List;

import com.starview.platform.data.type.Location;
import com.starview.star.compiler.ast.Apply;
import com.starview.star.compiler.ast.IAbstract;
import com.starview.star.compiler.util.PrettyPrintDisplay;

@SuppressWarnings("serial")
public class FmtApply implements FmtBuildOp
{
  private final FmtBuildOp op, argOps[];

  public FmtApply(FmtBuildOp op, FmtBuildOp args[])
  {
    this.op = op;
    this.argOps = args;
  }

  @Override
  public IAbstract build(IAbstract[] env, Location loc)
  {
    List<IAbstract> args = new ArrayList<IAbstract>();
    for (int ix = 0; ix < argOps.length; ix++)
      args.add(argOps[ix].build(env, loc));
    return new Apply(loc, op.build(env, loc), args);
  }

  @Override
  public void prettyPrint(PrettyPrintDisplay disp)
  {
    op.prettyPrint(disp);
    disp.append("@(");
    disp.prettyPrint(argOps, ", ");
    disp.append(")");
  }
}
